package com.example.parkingproject.controller;

import com.example.parkingproject.jopo.dto.AddCarDto;
import com.example.parkingproject.jopo.entity.carIn;
import com.example.parkingproject.jopo.vo.CarListVo;
import com.example.parkingproject.jopo.vo.StopHistoryVo;
import com.example.parkingproject.result.JsonResult;
import com.example.parkingproject.service.CarService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/car")
public class carController {
    @Autowired
    CarService carService;

    @RequestMapping("/carIn")
    public JsonResult carIn(@RequestBody carIn carIn) {
        carService.carIn(carIn);
        return JsonResult.ok();
    }

    @RequestMapping("/carOut")
    public JsonResult<Double> carOut(String carId) {
        log.debug("传入参数{}", carId);
        Double price = carService.carOut(carId);
        return JsonResult.ok(price);
    }


    @RequestMapping("/getCarList")
    public JsonResult<List<CarListVo>> getCarList(String cardId) {
        List<CarListVo> list = carService.getCarList(cardId);
        log.debug("获取到的参数列表{}", list);
        return JsonResult.ok(list);
    }

    @RequestMapping("/addNewCar")
    public JsonResult addNewCar(@RequestBody AddCarDto addCarDto) {
        log.debug("传入参数{}", addCarDto);
        carService.addNewCar(addCarDto);
        return JsonResult.ok();
    }

    @RequestMapping("/getHistory")
    public JsonResult<List<StopHistoryVo>> getHistory() {
        List<StopHistoryVo> list = carService.getHistory();
        log.debug("返回参数{}", list);
        return JsonResult.ok(list);
    }

    @RequestMapping("/search")
    public JsonResult<List<StopHistoryVo>> search(@RequestBody StopHistoryVo stopHistoryVo) {
        log.debug("传入参数{}", stopHistoryVo);
        List<StopHistoryVo> list = carService.search(stopHistoryVo);
        return JsonResult.ok(list);
    }


    @RequestMapping("/getDayHistory")
    public JsonResult<Integer> getDayHistory() {
        Integer count = carService.getDayHistory();
        log.debug("查询出参数{}", count);
        return JsonResult.ok(count);
    }

    @RequestMapping("/getMonthPrice")
    public JsonResult<Double> getMonthPrice() {
        Double price = carService.getMonthPrice();
        log.debug("传出参数{}价格", price);
        return JsonResult.ok(price);
    }

    @RequestMapping("/weekend")
    public JsonResult<List<Integer>> weekend() {
        List<Integer> list = carService.weekend();
        return JsonResult.ok(list);
    }

    @RequestMapping("/orderPrice")
    public JsonResult<List<Integer>> orderPrice() {
        List<Integer> list = carService.orderPrice();
        return JsonResult.ok(list);
    }
}
